Next | Prev | Up | Top | Contents | Index

Programming Bus-Master DMA

Bus-master DMA is performed by an EISA card that has bus-master logic. The card generates the DMA bus cycles, and provides the target memory address to store or retrieve data.

The device driver sets up Bus-master DMA by programming the card with a target physical address and length of data. Some cards support scatter/gather operations, in which the card is programmed with a list of memory pages and their lengths, and the card transfers a stream of data across all of the pages. However, programming an EISA bus master card is a highly hardware-dependent operation. The cards vary widely in their capabilities and programming methods.

The key programming issue for a device driver is locating the target memory buffers in system memory, so as to be able to program the EISA card with correct physical memory addresses.

The kernel provides functions for mapping memory for DMA. The functions that operate on EISA DMA maps are summarized in Table 17-3.

Functions That Operate on DMA Maps
FunctionHeader FilesCan SleepPurpose
dma_map(D3) dmamap.h & types.h & sema.hNPrepare DMA mapping.
dma_mapaddr(D3) dmamap.h & types.h & sema.hNReturn the target physical address for a given map and address.
dma_mapalloc(D3) dmamap.h & types.h & sema.hYAllocate a DMA map.
dma_mapfree(D3) dmamap.h & types.h & sema.hNFree a DMA map.

A device driver allocates a DMA map using dma_mapalloc(). This is typically done in the pfxedtinit() entry point, provided that the maximum I/O size is known at that time (see "Entry Point edtinit()").

A DMA map is used prior to a DMA transfer into or out of a buffer in kernel virtual space. The function dma_map() takes a DMA map, a buffer address, and a length. It relates the buffer address to physical addresses for use in DMA, and returns the length mapped. The returned length is typically less than the length of the buffer. This is because, for EISA, the function does not support scatter/gather, so the mapping must stop at the first page boundary.

After calling dma_map(), the device driver calls dma_mapaddr() to get the physical address corresponding to the current map. This is the address that is programmed into the EISA bus master card as a target address for a segment of the transfer up to one page in size.

Repeated calls to dma_map() and dma_mapaddr() can be used to map successive pages, until the EISA card is loaded with as many transfer segment addresses as it supports.


Next | Prev | Up | Top | Contents | Index